﻿var selectOption = {
    fileUploadIP: InitialParameter("/Config.json")["fileUploadOrigin"].value,
    org: "",
    catalogid: "",
    filter: null,
    orderby: null,
    catalogTree: null,
    filters: {
        year: null,
        jingdu: null,
        bili: null,
        name: null,
        zylx: null,
        xzqh: null,
        orderby: "resource_id",
        desc: true,
        repeat: false
    }
} 
var form,layer
layui.use(['form', 'layer'], function () {
    form = layui.form
    , layer = layui.layer
    form.render();
    initDropDown(datas);
});
var userinfo = {
    FK_DEPT: getCookie("portaluserdept"),
    ISMANAGER: getCookie("portalusermanager"),
    userNo: getCookie("portaluserno")
};
var baseUrl = getBaseplatformPort();
function getResourceFilter() {
    var thisResult = null;
    var filters = selectOption.filters;
    if (filters.year) {
        if (filters.year == "null") {
            if (thisResult) {
                thisResult += " and tb.year is null ";
            } else {
                thisResult = " tb.year is null ";
            }
        } else {
            if (thisResult) {
                thisResult += " and tb.year = '" + filters.year + "' ";
            } else {
                thisResult = " tb.year = '" + filters.year + "' ";
            }
        }
    }
    if (filters.jingdu) {

    }
    if (filters.bili) {

    }
    if (filters.name && filters.name != "%%") {
        if (thisResult) {
            thisResult += " and (tb.name like '" + filters.name + "' or tb.resourceid in (select resourceid from TB_XMLDOC where contains(xmlmeta,'" + filters.name + "')>0)) ";
        } else {
            thisResult = " (tb.name like '" + filters.name + "' or tb.resourceid in (select resourceid from TB_XMLDOC where contains(xmlmeta,'" + filters.name + "')>0)) ";
        }
    }
    if (filters.zylx) {
        if (thisResult) {
            thisResult += " and tb.zylx = '" + filters.zylx + "' ";
        } else {
            thisResult = " tb.zylx = '" + filters.zylx + "' "
        }
    }
    if (filters.xzqh) {
        if (thisResult) {
            thisResult += " and tb.area like '" + filters.xzqh + "' ";
        } else {
            thisResult = " tb.area like '" + filters.xzqh + "' "
        }
    }
    //资源过滤条件
    selectOption.filter = thisResult;

    //资源排序
    if (filters.repeat) {
        selectOption.filters.desc = !selectOption.filters.desc;
    }
    if (filters.desc) {
        selectOption.orderby = " nlssort(" + filters.orderby + ",'NLS_SORT=SCHINESE_PINYIN_M') desc ";
        //selectOption.orderby = " " + filters.orderby + "  desc ";
    } else {
        selectOption.orderby = " nlssort(" + filters.orderby + ",'NLS_SORT=SCHINESE_PINYIN_M') asc ";
        //selectOption.orderby = " " + filters.orderby + " asc ";
    }
}
$(document).ready(function () {
    userORG = getUserORG();
    //初始化目录树
    var strCatalogData = getCatalogData();
    var jsonCatalogTree = getTreeCatalog(JSON.parse(strCatalogData).data);
    selectOption.catalogTree = jsonCatalogTree;
    //var jsonCatalogData = changeStrToJsonOrArray(strCatalogData, null, true, "json");
    //var jsonCatalogTree = getTreeCatalog(jsonCatalogData);
    initializeMenu(jsonCatalogTree);

    //初始化资源信息
    //存储查询信息
    selectOption.org = userORG;
    selectOption.catalogid = "";
    var resourceType = getQueryString("mode");
    //if (resourceType) {
    //    selectOption.filters.zylx = resourceType;
    //}
    switch (resourceType) {
        case "1":
        case "2":
        case "3":
        case "4":
        case "5":
            selectOption.filters.zylx = resourceType;
            break;
        case "default":
        default:
            selectOption.filters.zylx = null;
            break;

    }
    strCatalogData = getResourceByType(userORG, "", 1);

    jsonCatalogData = changeStrToJsonOrArray(strCatalogData, null, true, "json");
    initializeResource(jsonCatalogData, 8);
    //strCatalogData = getORGResource(userORG);

    $("#CatalogList .mainL-hd a").click(function () {
        selectOption.catalogid = "";
        strCatalogData = getResourceByType(selectOption.org, "", 1);
        jsonCatalogData = changeStrToJsonOrArray(strCatalogData, null, true, "json");
        initializeResource(jsonCatalogData, 8);
    });
    $("#ul_menuList li .mainNavTitle").click(function () {
        var catalogid = $(this).parent().attr("catalogid");
        selectOption.catalogid = catalogid;
        strCatalogData = getResourceByType(selectOption.org, catalogid, 1);
        jsonCatalogData = changeStrToJsonOrArray(strCatalogData, null, true, "json");
        initializeResource(jsonCatalogData, 8);
    });
});
//定义分组变量
//var groupIndex = 1, eachGroupNum = 4;
var groupsInfo = {
    "nowindex": 1,
    "eachgroupnum": 32,
    "totalnum": 0,
    "totalpage": 0,
    "lastResult": null
}
//从数据库读取资源目录数据
function getCatalogData() {
    var thisresult;
    $.ajax({
        type: "post",
        async: false,
        url: baseUrl + "catalog/getTreeList",
        //url: "/BaseAshx/Resource/CatalogManage.ashx",
        data: //发送到服务器的参数
        {
            //mtype: "CatalogManage_GetTreeList"
        },
        datatype: "json",
        success: function (result) {
            thisresult = result;
        },
        error: function (err) {
            //if (err.status == 405)
            //    top.location.href = '/login/LoginNew.aspx';
            layer.msg(err,{
                shade: 0.3,
                time: 1000 // 1秒关闭
            })
        }
    });
    return thisresult;
}
//从数据库读取相应类资源数据  参数为属性值数组
function getResourceByType(orgID, catalogid, pageIndex) {
    var thisresult;
    var startnum = 1,
        endnum = 0;
    var eachPageNum = groupsInfo["eachgroupnum"];
    //pageIndex = pageIndex ? pageIndex : 1;
    if (pageIndex) {
        startnum = (pageIndex - 1) * eachPageNum + 1;
        endnum = pageIndex * eachPageNum;
        groupsInfo["nowindex"] = pageIndex;
        if (pageIndex != 1) {
            var arr_queryResult = groupsInfo.lastResult;
            var num_start = startnum - 1;
            var num_end = arr_queryResult.length > endnum ? endnum : arr_queryResult.length;
            var arr_result = new Array();
            arr_result.push({
                "totalnum": arr_queryResult.length,//查询结果总数
                "returnnum": num_end - num_start//返回条数
            })
            for (var i = num_start; i < num_end; i++) {
                arr_result.push(arr_queryResult[i]);
            }
            thisresult = JSON.stringify(arr_result);
            return thisresult;
        }
    }
    //添加资源过滤信息
    getResourceFilter();
    selectOption.filters.repeat = true;
    $.ajax({
        type: "post",
        async: false,
        //url: "/BaseAshx/Resource/ResourceAshx.ashx",
        url: baseUrl + "resource/getResourceByType",
        data: //发送到服务器的参数
        {
            //stype: "getResourceByType",
            orgid: orgID,
            catalogid: catalogid,
            filter: selectOption.filter,
            orderby: selectOption.orderby,
            startnum: startnum,
            endnum: 0//endnum
        },
        datatype: "json",
        success: function (result) {
            result = JSON.stringify(JSON.parse(result).data)
            if (result == "") {
                result = [{
                    "totalnum": 0,
                    "returnnum": 0
                }]
                thisresult = JSON.stringify(result);
            }
            else if (!pageIndex) {
                //thisresult = result;
                var arr_queryResult = JSON.parse(result);
                var item0 = {
                    "totalnum": arr_queryResult.length,//查询结果总数
                    "returnnum": arr_queryResult.length//返回条数,全部返回
                };
                arr_queryResult.insert(0, item0);
                thisresult = JSON.stringify(arr_result);
            }
            else {
                var arr_queryResult = JSON.parse(result);
                groupsInfo.lastResult = arr_queryResult;//查询结果保存
                var arr_result = new Array();
                var num_start = startnum - 1;
                var num_end = arr_queryResult.length > endnum ? endnum : arr_queryResult.length;

                arr_result.push({
                    "totalnum": arr_queryResult.length,//查询结果总数
                    "returnnum": num_end - num_start//返回条数
                });
                for (var i = num_start; i < num_end; i++) {
                    arr_result.push(arr_queryResult[i]);
                }
                thisresult = JSON.stringify(arr_result);
            }
        },
        error: function (err) { 

            // if (err.status == 405)
            //     top.location.href = '/login/LoginNew.aspx';
        }
    });
    return thisresult;
}

function getResourceTotalNum(orgID, typearr) {
    //var thisresult;
    //var resourcetype = "";
    //var charasii, char;
    //if (typearr == "1=1") {
    //    resourcetype = typearr;
    //}
    //else {
    //    for (var i = 0; i < typearr.length; i++) {
    //        charasii = 65 + i;
    //        char = asiiToStr(charasii);
    //        if (i == 0) {
    //            resourcetype = "ATTR_" + char + " like '%" + typearr[i] + "%' ";
    //        }
    //        else {
    //            resourcetype += " and ATTR_" + char + " like '%" + typearr[i] + "%' ";
    //        }
    //    }
    //}
    //}
    //$.ajax({
    //    type: "post",
    //    async: false,
    //    url: "/BaseAshx/Resource/ResourceAshx.ashx",
    //    data: //发送到服务器的参数
    //        {
    //            stype: "getResourceTotalNum",
    //            orgid: orgID,
    //            resourcetype: resourcetype
    //        },
    //    datatype: "json",
    //    success: function (result) {
    //        thisresult = result;
    //    },
    //    error: function (err) {
    //        if (err.status == 405)
    //            top.location.href = '/login/LoginNew.aspx';
    //    }
    //});
    //return thisresult;
}
//获取资源目录树结构数据
function getTreeCatalog(CatalogTreeData) {
    var thisResult = {};
    var oneCatalog, catalogid, catalogname;
    for (var i = 0; i < CatalogTreeData.length; i++) {
        oneCatalog = CatalogTreeData[i];
        catalogid = oneCatalog.ID;
        if (catalogid.length / 3 == 1) {
            thisResult[catalogid] = {
                name: oneCatalog.NAME,
                lower: {}
            }
        } else if (catalogid.length / 3 == 2) {
            thisResult[catalogid.slice(0, 3)].lower[catalogid] = {
                name: oneCatalog.NAME,
                lower: {}
            }
        } else if (catalogid.length / 3 == 3) {
            thisResult[catalogid.slice(0, 3)].lower[catalogid.slice(0, 6)].lower[catalogid] = {
                name: oneCatalog.NAME,
                lower: {}
            }
        } else if (catalogid.length / 3 == 4) {
            thisResult[catalogid.slice(0, 3)].lower[catalogid.slice(0, 6)].lower[catalogid.slice(0, 9)].lower[catalogid] = {
                name: oneCatalog.NAME,
                lower: {}
            }
        }
    }
    return thisResult;
    var attrArr = ["ATTR_A", "ATTR_B", "ATTR_C", "ATTR_D", "ATTR_E", "ATTR_F", "ATTR_G", "ATTR_H", "ATTR_I", "ATTR_J"];
    var attrone;
    var catalogone;
    for (var key in CatalogTreeData) {
        catalogone = CatalogTreeData[key];
        if (catalogone["ATTR_A"] != "") {
            if (!thisResult[catalogone["ATTR_A"]]) {
                thisResult[catalogone["ATTR_A"]] = {};
            }
            if (catalogone["ATTR_B"] != "") {
                if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]]) {
                    thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]] = {};
                }
                if (catalogone["ATTR_C"] != "") {
                    if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]]) {
                        thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]] = {};
                    }
                    if (catalogone["ATTR_D"] != "") {
                        if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]]) {
                            thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]] = {};
                        }
                        if (catalogone["ATTR_E"] != "") {
                            if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]]) {
                                thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]] = {};
                            }
                            if (catalogone["ATTR_F"] != "") {
                                if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]]) {
                                    thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]] = {};
                                }
                                if (catalogone["ATTR_G"] != "") {
                                    if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]][catalogone["ATTR_G"]]) {
                                        thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]][catalogone["ATTR_G"]] = {};
                                    }
                                    if (catalogone["ATTR_H"] != "") {
                                        if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]][catalogone["ATTR_G"]][catalogone["ATTR_H"]]) {
                                            thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]][catalogone["ATTR_G"]][catalogone["ATTR_H"]] = {};
                                        }
                                        if (catalogone["ATTR_I"] != "") {
                                            if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]][catalogone["ATTR_G"]][catalogone["ATTR_H"]][catalogone["ATTR_I"]]) {
                                                thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]][catalogone["ATTR_G"]][catalogone["ATTR_H"]][catalogone["ATTR_I"]] = {};
                                            }
                                            if (catalogone["ATTR_J"] != "") {
                                                if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]][catalogone["ATTR_G"]][catalogone["ATTR_H"]][catalogone["ATTR_I"]][catalogone["ATTR_J"]]) {
                                                    thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]][catalogone["ATTR_G"]][catalogone["ATTR_H"]][catalogone["ATTR_I"]][catalogone["ATTR_J"]] = {};
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return thisResult;
}

//初始化资源目录
function initializeMenu(CatalogTree) {
    var ulNode = getNodeByID("ul_menuList");
    var dataCatalog_1 = CatalogTree; //获取第一级数据☜☜☜☜☜☜☜☜☜☜☜☜☜☜☜☜☜☜☜
    var dataCatalog_2 = null;
    var dataCatalog_3 = null;
    var dataCatalog_4 = null;
    var num_1 = 1;
    for (var key_1 in dataCatalog_1) {
        var newli = createNode("li");
        newli.setAttribute("attrtype", dataCatalog_1[key_1].name);
        newli.setAttribute("catalogid", key_1);

        //标题
        var newDiv_title = createNode("div");
        newDiv_title.className = "mainNavTitle";
        newDiv_title.innerHTML = dataCatalog_1[key_1].name;
        newli.appendChild(newDiv_title);

        //tab
        var newDiv_tab = createNode("div");
        newDiv_tab.className = "menu-tab";
        var tab_content = getTabContent(dataCatalog_1[key_1].name);
        //if (tab_content.length > 15) {
        //    tab_content = tab_content.slice(0, 15) + "...";
        //}
        $(newDiv_tab).append(tab_content);
        newli.appendChild(newDiv_tab);

        //更多
        var newSpan_more = createNode("span");
        newSpan_more.className = "menu-more";
        newSpan_more.innerHTML = "更多";
        newli.appendChild(newSpan_more);

        //二级菜单
        var newDiv_EJ = createNode("div");
        newDiv_EJ.className = "menu-panel";

        //二级菜单头▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
        var newDiv_head_EJ = createNode("div"); //二级菜单头
        newDiv_head_EJ.className = "menu-panel-hd";
        //二级菜单头表格
        var num_2 = 1;
        var newTable_EJ = createNode("table");
        newTable_EJ.id = "tb_" + num_1;
        var newTr_EJ = createNode("tr");
        dataCatalog_2 = CatalogTree[key_1].lower; //获取第二级数据☜☜☜☜☜☜☜☜☜☜☜☜☜☜☜☜☜☜☜
        if (getJsonLength(dataCatalog_2) != 0) {
            var thisTrCells = 0;
            for (var key_2 in dataCatalog_2) {
                thisTrCells++;
                var newTD = createNode("td");
                newTD.innerHTML = dataCatalog_2[key_2].name;
                newTD.setAttribute("attrtype", dataCatalog_1[key_1].name + "|" + dataCatalog_2[key_2].name);
                newTD.setAttribute("catalogid", key_2);
                newTD.id = "tb_" + num_1 + "_" + num_2;
                newTD.setAttribute("parm", "tb_" + num_1 + "|||" + num_2 + "|||" + getJsonLength(dataCatalog_2));
                newTD.onclick = function (evt) {
                    var parmArr = evt.target.attributes.parm.value.split("|||");
                    VisibleCalalogMenu(parmArr[0], parmArr[1], parmArr[2]);
                    clickCatalog(evt.target);
                };
                num_2++;
                newTr_EJ.appendChild(newTD);
                if (thisTrCells % 3 == 0) {
                    newTable_EJ.appendChild(newTr_EJ);
                    newTr_EJ = createNode("tr");
                }
            }
            newTable_EJ.appendChild(newTr_EJ); //行添加到表格
            newDiv_head_EJ.appendChild(newTable_EJ); //表格添加到头
            newDiv_EJ.appendChild(newDiv_head_EJ); //头添加到二级div
            //二级菜单头▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲

            var newDiv_SJ_1 = createNode("div");
            newDiv_SJ_1.className = "menu-panel-sub1";
            var newDiv_SJ_2 = createNode("div");
            newDiv_SJ_2.className = "menu-panel-sub2";
            var newDiv_SJ_child = null;
            var newTable_SJ = null;
            var newTr_SJ = null;
            var newTd_SJ = null;
            var num_3 = 0;
            for (var key_2 in dataCatalog_2) {
                num_3++;
                dataCatalog_3 = dataCatalog_2[key_2].lower; //获取第三级数据☜☜☜☜☜☜☜☜☜☜☜☜☜☜☜☜☜☜☜
                if (getJsonLength(dataCatalog_3) == 0) {
                    //continue;
                }
                if (true) { //如果还有子目录
                    newDiv_SJ_child = createNode("div");
                    newDiv_SJ_child.id = "tb_" + num_1 + "_" + num_3 + "s";
                    if (num_3 != 1) {
                        newDiv_SJ_child.style.display = "none";
                    } else {
                        newDiv_SJ_child.style.display = "";
                    }

                    for (var key_3 in dataCatalog_3) {
                        newTable_SJ = createNode("table");
                        newTr_SJ = createNode("tr");
                        newTd_SJ = createNode("th");
                        newTd_SJ.colSpan = getJsonLength(dataCatalog_3);
                        newTd_SJ.innerHTML = "<i class='fa fa-folder-open'></i>" + dataCatalog_3[key_3].name;
                        newTd_SJ.setAttribute("attrtype", dataCatalog_1[key_1].name + "|" + dataCatalog_2[key_2].name + "|" + dataCatalog_3[key_3].name);
                        newTd_SJ.setAttribute("catalogid", key_3);
                        newTd_SJ.onclick = function (evt) {
                            clickCatalog(evt.target);
                        }
                        newTr_SJ.appendChild(newTd_SJ);
                        newTable_SJ.appendChild(newTr_SJ); //添加三级表格第一行

                        dataCatalog_4 = dataCatalog_3[key_3].lower; //获取第四级数据☜☜☜☜☜☜☜☜☜☜☜☜☜☜☜☜☜☜☜
                        if (getJsonLength(dataCatalog_4) != 0) {
                            newTr_SJ = createNode("tr");
                            thisTrCells = 0;
                            for (var key_4 in dataCatalog_4) {
                                thisTrCells++;
                                newTd_SJ = createNode("td");
                                newTd_SJ.style.width = "33%";
                                newTd_SJ.innerHTML = dataCatalog_4[key_4].name;
                                newTd_SJ.setAttribute("attrtype", dataCatalog_1[key_1].name + "|" + dataCatalog_2[key_2].name + "|" + dataCatalog_3[key_3].name + "|" + dataCatalog_4[key_4].name);
                                newTd_SJ.setAttribute("catalogid", key_4);
                                newTd_SJ.onclick = function (evt) {
                                    clickCatalog(evt.target);
                                };
                                newTr_SJ.appendChild(newTd_SJ);
                                if (thisTrCells % 3 == 0) {
                                    newTable_SJ.appendChild(newTr_SJ);
                                    newTr_SJ = createNode("tr");
                                }
                            }
                            newTable_SJ.appendChild(newTr_SJ); //添加有四级的三级表格
                        }
                        newDiv_SJ_child.appendChild(newTable_SJ)
                    }
                    newDiv_SJ_1.appendChild(newDiv_SJ_child);
                }
                //else {//没有子目录
                //    newTable_SJ = createNode("table");
                //    newTable_SJ.style.display = "none";
                //    newTable_SJ.id = "tb_" + dataCatalog_2[key_2].ID + "s";
                //    console.log(dataCatalog_2[key_2].ID);
                //    newTr_SJ = createNode("tr");
                //    thisTrCells = 0;
                //    for (var key_3 in dataCatalog_3) {
                //        thisTrCells++;
                //        newTd_SJ = createNode("td");
                //        newTd_SJ.innerHTML = dataCatalog_3[key_3].name;
                //        newTd_SJ.setAttribute("catalogid", key_3);
                //        newTd_SJ.onclick = function (evt) {
                //            clickCatalog(this);
                //        };
                //        newTr_SJ.appendChild(newTd_SJ);
                //        if (thisTrCells % 2 == 0) {
                //            newTable_SJ.appendChild(newTr_SJ);
                //            newTr_SJ = createNode("tr");
                //        }
                //    }
                //    newTable_SJ.appendChild(newTr_SJ);
                //    newDiv_SJ_2.appendChild(newTable_SJ);
                //}
            }
            newDiv_EJ.appendChild(newDiv_SJ_1);
            //newDiv_EJ.appendChild(newDiv_SJ_2);

            newli.appendChild(newDiv_EJ); //二级div添加到li标签
            ulNode.appendChild(newli); //li标签添加到目录
            num_1++;
        }
    }
}
//获取一级目录下二级tab内容
function getTabContent(attrA) {
    var jsondata = getCatalogLevelTwo(attrA);
    jsondata = changeStrToJsonOrArray(jsondata, null, true, "json");
    var tableTab = document.createElement("table");
    tableTab.className = "tableTab";

    var trTab, oneData, oneTitle, showtitle, tdTab;
    var num = 1;
    trTab = document.createElement("tr");
    for (var key in jsondata) {
        oneData = jsondata[key];
        tdTab = document.createElement("td");
        oneTitle = oneData.ATTR_B;
        //if (false) {
        //    showtitle = oneTitle.slice(0, 5) + "...";
        //}
        //else {
        //    showtitle = oneTitle;
        //}
        tdTab.innerHTML = "<a href='javascript:void(0)' onclick='clickCatalog(this)' title='" + oneTitle + "' attrtype='" + attrA + "|" + jsondata[key].ATTR_B + "' catalogid='" + oneData.CATALOGID + "'>" + oneTitle + "</a>";
        trTab.appendChild(tdTab);

        if (num % 2 == 0) {
            tableTab.appendChild(trTab);
            trTab = document.createElement("tr");
        } else {
            tdTab.className = "tdTabLeft";
        }
        num++;
    }
    if (num % 2 == 0) {
        tableTab.appendChild(trTab);
    }
    return tableTab;
    //var thisResult = "";
    //var a_one = "";
    //var num = 1;
    //for (var key in jsondata) {
    //    if (num>6) {
    //        break;
    //    }
    //    a_one = "<a style='height:20px;' href='#' onclick='clickCatalog(this)' title='" + jsondata[key].ATTR_B + "' attrtype='" + attrA + "|" + jsondata[key].ATTR_B + "' >" + jsondata[key].ATTR_B + "</a>";
    //    if (num%2==0) {
    //        thisResult += a_one;
    //    }
    //    else {
    //        if (num==1) {
    //            thisResult = a_one;
    //        }
    //        else {
    //            thisResult += "<br/>" + a_one;
    //        }
    //    }
    //   num++;
    //}
}
//点击资源目录条目
function clickCatalog(node) {
    var thisResult = new Array();
    var catalogid = node.attributes.catalogid.value;
    thisResult = getResourceByType(selectOption.org, catalogid, 1);
    //var attrtype = node.attributes.attrtype.value;
    //thisResult = attrtype.split("|");

    //存储查询信息
    selectOption.catalogid = catalogid;

    thisResult = changeStrToJsonOrArray(thisResult, null, true, "json");
    //thisResult = {};
    initializeResource(thisResult, 8);
    //return thisResult;
}
//填充资源展示
function initializeResource(dataResourceJson, eachPageNum, attrtype) {
    var flag = false;
    if (eachPageNum) {
        if (eachPageNum == 8) {
            flag = true;
        }
    } else {
        eachPageNum = 8;
        flag = true;
    }
    var num_result = dataResourceJson["item1"];
    delete dataResourceJson.item1;
    var dataResourceLength = num_result.returnnum; //getJsonLength(dataResourceJson);
    var dataListNode = getNodeByID("DataList");
    dataListNode.innerHTML = "";
    var buttonNode = getNodeByID("button");
    buttonNode.innerHTML = "";
    var pagenum = parseInt(dataResourceLength / eachPageNum);
    if (dataResourceLength % eachPageNum != 0) {
        pagenum++;
    }

    ////添加页面信息
    var thisPageNum = 0;
    if (pagenum == 0) {
        pagenum++;
    }
    for (var i = 0; i < pagenum; i++) {
        if (i + 1 < pagenum) {
            thisPageNum = eachPageNum;
        } else {
            thisPageNum = dataResourceLength - (pagenum - 1) * eachPageNum;
        }
        var newCell_list = createNode("cell");
        newCell_list.style.height = "90%";
        newCell_list.style.width = "100%";
        newCell_list.style.backgroundColor = "#fff";
        if (i == 0) {
            newCell_list.style.display = "block";
        }
        var newDiv_list = createNode("div");
        newDiv_list.style.textAlign = "center";
        newDiv_list.style.width = "100%";

        //页面头
        var newDiv_pagehead = createNode("div");
        newDiv_pagehead.style.marginLeft = "22px";
        newDiv_pagehead.style.textAlign = "left";
        newDiv_pagehead.style.color = "white";
        var newI_pagehead = createNode("i");
        newI_pagehead.className = "fa fa-chevron-circle-right";
        newI_pagehead.style.color = "#a4e1fd";
        newI_pagehead.style.fontSize = "16px";
        newDiv_pagehead.appendChild(newI_pagehead);
        var newFont_pagehead = createNode("font");
        newFont_pagehead.style.color = "#a4e1fd";
        newFont_pagehead.innerHTML = "&nbsp;&nbsp;当前位置：";
        newDiv_pagehead.appendChild(newFont_pagehead);
        if (selectOption.catalogid == "") {
            newDiv_pagehead.innerHTML += "全部数据";
        } else {
            var pageheadInnerHTML = "";
            var jsonOBJ = selectOption.catalogTree;
            for (var k = 0; k < selectOption.catalogid.length / 3; k++) {
                if (jsonOBJ.hasOwnProperty("lower")) {
                    jsonOBJ = jsonOBJ.lower[selectOption.catalogid.slice(0, 3 * (k + 1))];
                    pageheadInnerHTML += " > " + jsonOBJ.name
                } else {
                    jsonOBJ = jsonOBJ[selectOption.catalogid.slice(0, 3 * (k + 1))];
                    pageheadInnerHTML = jsonOBJ.name
                }
            }
            newDiv_pagehead.innerHTML += pageheadInnerHTML;
        }
        //if (attrtype && attrtype!="1=1") {
        //    var newattrtype = attrtype.split("|");
        //    var path = null;
        //    for (var j = 0; j < newattrtype.length; j++) {
        //        path = null;
        //        if (j == 0) {
        //            newDiv_pagehead.innerHTML += newattrtype[j];
        //        }
        //        else {
        //            newDiv_pagehead.innerHTML += (">" + newattrtype[j]);
        //        }
        //    }
        //}
        //else {
        //    newDiv_pagehead.innerHTML += "全部数据";
        //}
        if (dataResourceLength == 0) {
            newDiv_pagehead.innerHTML += "&nbsp&nbsp<b style='color:orange;'>暂无数据！！！</b>";
            newDiv_list.appendChild(newDiv_pagehead);
            newCell_list.appendChild(newDiv_list);
            dataListNode.appendChild(newCell_list);
            $(".groupInfoTable").remove();
            return;
        }

        newDiv_list.appendChild(newDiv_pagehead);

        //页面内容  第一行
        var newDiv_row1 = createNode("div");
        newDiv_row1.className = "row row_width";
        newDiv_row1.style.margin = "20px auto 40px auto";
        var thisTrNum = 0;
        if (thisPageNum >= eachPageNum / 2) {
            thisTrNum = eachPageNum / 2;
        } else {
            thisTrNum = thisPageNum;
        }
        for (var j = 0; j < thisTrNum; j++) { //循环创建每个数据源
            var newDiv_inTr = createNode("div");
            //if (flag) {
            newDiv_inTr.className = "col-md-3 col-sm-6";
            //}
            //else {
            //    newDiv_inTr.className = "col-md-2 col-sm-5";
            //}

            var newDiv_productGrid = createNode("div");
            newDiv_productGrid.className = "product-grid";


            var newDiv_productImage = createNode("div");
            newDiv_productImage.className = "product-image";
            var index = (i * eachPageNum) + j + 1;
            var oneResource = getOneResourceInfo(index, dataResourceJson);
            var iconArr = oneResource.ZYLX;
            for (var k = 0; k < iconArr.length; k++) {
                newDiv_productImage.appendChild(getIconClassName(k, iconArr));
            }
            var newA_link = createNode("a");
            newA_link.href = "javascript:void(0);";
            var newImg_link = createNode("img");
            newImg_link.className = "pic-1";
            newImg_link.src = "/img/BasePlatform/resource/" + oneResource.ZYTB;
            newImg_link.alt = oneResource.NAME + ".jpg";
            newImg_link.setAttribute("resourceguid", oneResource.RESOURCE_ID);
            newImg_link.title = oneResource.NAME;
            newImg_link.style.cursor = "pointer";
            newA_link.appendChild(newImg_link);
            newDiv_productImage.appendChild(newA_link);
            newDiv_productGrid.appendChild(newDiv_productImage);


            var newDiv_productContent = createNode("div");
            newDiv_productContent.className = "product-content";
            var newH3_h3 = createNode("h3");
            newH3_h3.className = "title";
            newH3_h3.innerHTML = "<a href='javascript:void(0);'>" + oneResource.NAME + "</a>"
            newDiv_productContent.appendChild(newH3_h3);
            var newDiv_price = createNode("div");
            newDiv_price.className = "price";
            newDiv_price.innerHTML = getViewAndDownloadInfo(oneResource.ZYLX, oneResource.VIEWNUM, oneResource.DOWNNUM, oneResource.RUNNUM);
            newDiv_productContent.appendChild(newDiv_price);
            newDiv_productGrid.appendChild(newDiv_productContent);


            var newUl_social = createNode("ul");
            newUl_social.className = "social";
            newUl_social.setAttribute("resourceType", oneResource.ZYLX);
            newUl_social.setAttribute("guid", oneResource.RESOURCE_ID);
            newUl_social.setAttribute("sourceName", oneResource.NAME);
            newUl_social.setAttribute("position", oneResource.POSITION);
            newUl_social.innerHTML = getUlInerHTML(oneResource.ZYLX, oneResource.PERMISSIONS, oneResource);
            newDiv_productGrid.appendChild(newUl_social);


            newDiv_inTr.appendChild(newDiv_productGrid);
            newDiv_row1.appendChild(newDiv_inTr);
        }
        //补齐缺少的div
        for (var j = 0; j < eachPageNum / 2 - thisTrNum; j++) {
            var newDiv_inTr = createNode("div");
            //if (flag) {
            newDiv_inTr.className = "col-md-3 col-sm-6";
            //}
            //else {
            //    newDiv_inTr.className = "col-md-2 col-sm-5";
            //}
            newDiv_inTr.style.visibility = "hidden";
            newDiv_inTr.innerHTML = "<img class='pic-1' src='/img/BasePlatform/resource/default.jpg' />";
            newDiv_row1.appendChild(newDiv_inTr);
        }
        newDiv_list.appendChild(newDiv_row1);
        if (thisPageNum > eachPageNum / 2) {
            //页面内容  第二行
            var newDiv_row2 = createNode("div");
            newDiv_row2.className = "row row_width";
            newDiv_row2.style.margin = "30px auto 50px auto";

            for (var j = 0; j < thisPageNum - eachPageNum / 2; j++) {
                var newDiv_inTr = createNode("div");
                //if (flag) {
                newDiv_inTr.className = "col-md-3 col-sm-6";
                //}
                //else {
                //    newDiv_inTr.className = "col-md-2 col-sm-5";
                //}

                var newDiv_productGrid = createNode("div");
                newDiv_productGrid.className = "product-grid";

                var newDiv_productImage = createNode("div");
                newDiv_productImage.className = "product-image";

                var index = (i * eachPageNum) + j + eachPageNum / 2 + 1;
                var oneResource = getOneResourceInfo(index, dataResourceJson);
                var iconArr = oneResource.ZYLX;
                for (var k = 0; k < iconArr.length; k++) {
                    newDiv_productImage.appendChild(getIconClassName(k, iconArr));
                }
                var newA_link = createNode("a");
                newA_link.href = "javascript:void(0);";
                var newImg_link = createNode("img");
                newImg_link.className = "pic-1";
                newImg_link.src = "/img/BasePlatform/resource/" + oneResource.ZYTB;
                newImg_link.alt = oneResource.NAME + ".jpg";
                newImg_link.setAttribute("resourceguid", oneResource.RESOURCE_ID);
                newImg_link.title = oneResource.NAME;
                newImg_link.style.cursor = "pointer";
                newA_link.appendChild(newImg_link);
                newDiv_productImage.appendChild(newA_link);
                newDiv_productGrid.appendChild(newDiv_productImage);


                var newDiv_productContent = createNode("div");
                newDiv_productContent.className = "product-content";
                var newH3_h3 = createNode("h3");
                newH3_h3.className = "title";
                newH3_h3.innerHTML = "<a href='javascript:void(0);'>" + oneResource.NAME + "</a>"
                newDiv_productContent.appendChild(newH3_h3);
                var newDiv_price = createNode("div");
                newDiv_price.className = "price";
                newDiv_price.innerHTML = getViewAndDownloadInfo(oneResource.ZYLX, oneResource.VIEWNUM, oneResource.DOWNNUM, oneResource.RUNNUM);
                newDiv_productContent.appendChild(newDiv_price);
                newDiv_productGrid.appendChild(newDiv_productContent);


                var newUl_social = createNode("ul");
                newUl_social.setAttribute("resourceType", oneResource.ZYLX);
                newUl_social.setAttribute("guid", oneResource.RESOURCE_ID);
                newUl_social.setAttribute("sourceName", oneResource.NAME);
                newUl_social.setAttribute("position", oneResource.POSITION);
                newUl_social.className = "social";
                newUl_social.innerHTML = getUlInerHTML(oneResource.ZYLX, oneResource.PERMISSIONS, oneResource);
                newDiv_productGrid.appendChild(newUl_social);

                newDiv_inTr.appendChild(newDiv_productGrid);
                newDiv_row2.appendChild(newDiv_inTr);
            }
            newDiv_list.appendChild(newDiv_row2);
        }
        //newCell_list.appendChild(getResourceGroupInfo(attrtype));
        newCell_list.appendChild(newDiv_list);
        dataListNode.appendChild(newCell_list);
    }

    //添加分页
    for (var i = 0; i < pagenum; i++) {
        var newLi_pageCtrl = createNode("li");
        var newDiv_pageCtrl = createNode("div");
        if (i == 0) {
            newDiv_pageCtrl.style.backgroundColor = "#A10000";
        }
        newLi_pageCtrl.appendChild(newDiv_pageCtrl);
        buttonNode.appendChild(newLi_pageCtrl);
    }
    $(".groupInfoTable").remove();
    $(buttonNode).after(getResourceGroupInfo(num_result.totalnum)); //分组信息
    rollscript();

    //更改图片
    //$("#DataList img.pic-1").click(function (evt) {
    //   $("#changeResourceImg").click();
    // var ulNode = $(evt.currentTarget).attr("resourceguid");
    //$("#hid_cache_id").val(ulNode);
    //}); 
    $("#changeResourceImg").change(function () {
        //return;
        var file = this.files[0];
        var form = new FormData();
        form.append("stype", "updateResourceImg"); //实际业务的其他请求参数
        form.append("file", file); //第一个参数是后台读取的请求key值
        form.append("fileName", file.name);
        form.append("userno", getUser());
        form.append("guid", $("#hid_cache_id").val());
        var xhr = new XMLHttpRequest();
        var action = "/BaseAshx/Img/Img.ashx"; //上传服务的接口地址
        xhr.open("POST", action);
        xhr.send(form); //发送表单数据
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4 && xhr.status == 200) {
                console.log(xhr.responseText);
                if (xhr.responseText == "True") {
                    alert("更改成功，页面刷新后生效");
                }
                else {
                    alert("更改失败，请稍后重试");
                }
                //if (xhr.responseText == "False") {
                //    $(".file_upload_layer_ZYTB").val("fuw.jpg");
                //    $(".file_upload_arcgis_ZYTB").val("fuw.jpg");
                //    isTransit = false;
                //    alert("文件格式错误");
                //}
                //else {
                //    $(".file_upload_layer_ZYTB").val(xhr.responseText);
                //    $(".file_upload_arcgis_ZYTB").val(xhr.responseText);
                //    isTransit = true;
                //}
                //var resultObj = JSON.parse(xhr.responseText);//处理返回的数据......
            }
        };
        getNodeByID("changeResourceImg").value = null;
    });
}

//获取一条资源记录
function getOneResourceInfo(index, dataResourceJson) {
    var thisResult = null;
    var num = 1;
    for (var key in dataResourceJson) {
        if (index == num) {
            thisResult = dataResourceJson[key];
            break;
        }
        num++;
    }
    return thisResult;
}
//获取图标类名
function getIconClassName(index, iconStr) {
    var thisIconClassName = null;
    if (index == 0) {
        thisIconClassName = "icon ";
    } else {
        thisIconClassName = "icon" + (index + 1) + " ";
    }
    switch (iconStr.substring(index, index + 1)) {
        case "1":
            thisIconClassName += "BlueBack fa fa-database";
            break;
        case "2":
            thisIconClassName += "PurpleBack fa fa-globe";
            break;
        case "3":
            thisIconClassName += "OrangeBack fa fa-wrench";
            break;
        case "4":
            thisIconClassName += "GreenBack fa fa-map";
            break;
        case "5":
            thisIconClassName += "PinkBack fa fa-file-text";
            break;
        default:
            break;
    }
    var newDiv_icon = createNode("div");
    newDiv_icon.className = thisIconClassName;
    return newDiv_icon;
}
//获取资源对应浏览量、下载量、运行量
function getViewAndDownloadInfo(resourceType, viewNum, downNum, runNum) {
    var thisResult = null;
    viewNum = viewNum == "" ? 0 : viewNum;
    downNum = downNum == "" ? 0 : downNum;
    runNum = runNum == "" ? 0 : runNum;
    var viewInfo = "<i class='fa fa-eye'></i><span>" + viewNum + "</span>";
    var downInfo = "<i class='fa fa-download'></i><span>" + downNum + "</span>";
    var runInfo = "<i class='fa fa-play-circle-o'></i><span>" + runNum + "</span>";
    switch (resourceType.slice(0, 1)) {
        case "1":
            thisResult = viewInfo + "&nbsp;&nbsp;&nbsp;&nbsp;" + downInfo;
            break;
        case "2":
            thisResult = viewInfo;
            break;
        case "3":
            thisResult = viewInfo + "&nbsp;&nbsp;&nbsp;&nbsp;" + runInfo;
            break;
        case "4":
        case "5":
            thisResult = viewInfo + "&nbsp;&nbsp;&nbsp;&nbsp;" + downInfo;
            break;
        default:
            alert("操作有误！");
            thisResult = viewInfo;
            break;
    }
    return thisResult;
}
//获取对应操作
function getUlInerHTML(resourceType, resourcePermission, resourceInfo) {
    /**
     * 1：实体
     * 2：地图服务
     * 3：工具
     * 4：图件
     * 5：文件
     */

    var thisResult = "";
    var newLi_view = "<li><a href='javascript:void(0);' onclick='clickView(this," + resourceType.slice(0, 1) + ")' data-tip='加载到地图'><i class='fa fa-eye'></i></a></li>";

    var newLi_edit = "",
        newLi_download = "",
        newLi_rundemo = "",
        newLi_adddemo = "";
    // if (resourceInfo.COMPANY && resourceInfo.COMPANY.indexOf(userinfo.FK_DEPT) == 0 && (userinfo.ISMANAGER == "1" || userinfo.ISMANAGER == "2")) {
    //     newLi_edit = "<li><a href='javascript:void(0);' onclick='clickEdit(this," + resourceType.slice(0, 1) + ")' data-tip='编辑' ><i class='fa fa-edit'></i></a></li>";
    // }
    //if (resourcePermission.length > 0 && resourcePermission.slice(0, 1) == "1") {
    //    newLi_edit = "<li><a href='javascript:void(0);' onclick='clickEdit(this," + resourceType.slice(0, 1) + ")' data-tip='编辑' ><i class='fa fa-edit'></i></a></li>";
    //}
    if (resourcePermission.length > 1 && resourcePermission.slice(1, 2) == "1" && (userinfo.ISMANAGER == "1" || userinfo.ISMANAGER == "2")) {
        newLi_download = "<li><a href='javascript:void(0);' onclick='clickDownload(this," + resourceType.slice(0, 1) + ")' data-tip='下载'><i class='fa fa-download'></i></a></li>";
    }

    if (resourcePermission.length > 2 && resourcePermission.slice(2, 3) == "1") {
        newLi_adddemo = "<li><a href='javascript:void(0);' onclick='clickAdddemo(this)' data-tip='添加'><i class='fa fa-plus-square-o' style='font-size:20px;'></i></a></li>";
        newLi_rundemo = "<li><a href='javascript:void(0);' onclick='clickRundemo(this)' data-tip='运行'><i class='fa fa-play-circle-o' style='font-size:20px;'></i></a></li>";
    }
    switch (resourceType.slice(0, 1)) {
        case "1":
        case "2":
        case "3":
        case "4":
            thisResult = newLi_view + newLi_edit;
            break;
        //case "3":
            //thisResult = newLi_view + newLi_edit + newLi_rundemo;
            //thisResult = newLi_rundemo + (newLi_edit ? newLi_edit : newLi_view) + newLi_adddemo;
            break;
        case "5":
            thisResult = newLi_view + newLi_edit + newLi_download;
            break;
        default:
            //alert("操作有误！");
            //thisResult = newLi_view + newLi_edit + newLi_download;
            break;
    }
    return thisResult;
}

//复制json
function copyJson(jsonData) {
    var thisResult = null;
    var jsonLength = getJsonLength(jsonData);
    thisResult = jsonData;
    for (var key in jsonData) {
        jsonLength++;
        thisResult["item" + jsonLength] = jsonData[key];
    }
    return thisResult;
}

//生成资源分组信息
function getResourceGroupInfo(totalnum) {
    var dataResourceTotal = totalnum; //当前类型资源总数
    //var getResourceByTypeResult=getResourceByType(userORG, selectOption.catalogid);
    //if (!getResourceByTypeResult) {
    //    dataResourceTotal = 0;
    //    return "";
    //} else {
    //    dataResourceTotal = getJsonLength(JSON.parse(getResourceByTypeResult));
    //}

    groupsInfo["totalnum"] = dataResourceTotal; //资源总数
    var groupNum = parseInt(dataResourceTotal / groupsInfo.eachgroupnum);
    if (dataResourceTotal % groupsInfo.eachgroupnum != 0) {
        groupNum++;
    }
    groupsInfo["totalpage"] = groupNum;
    var table_groupInfo = createNode("table");
    table_groupInfo.className = "groupInfoTable";
    table_groupInfo.style = "width:90%;position:absolute;bottom:30px;left:5%;z-index:0;";
    var tr_groupInfo = createNode("tr");
    tr_groupInfo.setAttribute("catalogid", selectOption.catalogid);
    var td_groupInfo_1 = createNode("td");
    td_groupInfo_1.innerHTML = "<font>总共</font> " + groupsInfo.totalnum + " <font>条数据，每组</font> " + groupsInfo.eachgroupnum + " <font>条，共</font> " + groupsInfo.totalpage + " <font>组，当前第</font> " + groupsInfo.nowindex + " <font>组</font>";
    tr_groupInfo.appendChild(td_groupInfo_1);
    //var td_groupInfo_6 = createNode("td");
    //td_groupInfo_6.innerHTML = "";
    //tr_groupInfo.appendChild(td_groupInfo_6);
    var td_groupInfo_2 = createNode("td");
    td_groupInfo_2.style.width = "50%";
    td_groupInfo_2.style.textAlign = "right";
    td_groupInfo_2.innerHTML = "<a href='javascript:void(0)' class='groupInfoBtn first' onclick=changeGroupInfo(this)>首组</a>"
    + "&nbsp&nbsp<a href='javascript:void(0)' class='groupInfoBtn prev' onclick=changeGroupInfo(this)>上一组</a>"
    + "&nbsp&nbsp<a href='javascript:void(0)' class='groupInfoBtn next' onclick=changeGroupInfo(this)>下一组</a>"
    + "&nbsp&nbsp<a href='javascript:void(0)' class='groupInfoBtn last' onclick=changeGroupInfo(this)>尾组</a>";
    tr_groupInfo.appendChild(td_groupInfo_2);

    //var td_groupInfo_2 = createNode("td");
    //td_groupInfo_2.style.width = "3%";
    //td_groupInfo_2.innerHTML = "<a href='javascript:void(0)' class='groupInfoBtn first' onclick=changeGroupInfo(this)>首组</a>";
    //tr_groupInfo.appendChild(td_groupInfo_2);
    //var td_groupInfo_3 = createNode("td");
    //td_groupInfo_3.innerHTML = "<a href='javascript:void(0)' class='groupInfoBtn prev' onclick=changeGroupInfo(this)>上一组</a>";
    //td_groupInfo_3.style.width = "4%";
    //tr_groupInfo.appendChild(td_groupInfo_3);
    //var td_groupInfo_4 = createNode("td");
    //td_groupInfo_4.innerHTML = "<a href='javascript:void(0)' class='groupInfoBtn next' onclick=changeGroupInfo(this)>下一组</a>";
    //td_groupInfo_4.style.width = "4%";
    //tr_groupInfo.appendChild(td_groupInfo_4);
    //var td_groupInfo_5 = createNode("td");
    //td_groupInfo_5.innerHTML = "<a href='javascript:void(0)' class='groupInfoBtn last' onclick=changeGroupInfo(this)>尾组</a>";
    //td_groupInfo_5.style.width = "3%";
    //tr_groupInfo.appendChild(td_groupInfo_5);

    table_groupInfo.appendChild(tr_groupInfo);
    return table_groupInfo;
}
//更新资源组
function changeGroupInfo(node) {
    var catalogid = node.parentNode.parentNode.attributes.catalogid.value;
    var strResourceData;
    if ($(node).hasClass("first")) {
        if (groupsInfo.nowindex == 1) {
            alert("当前展示为第一组资源信息");
            return;
        }
        strResourceData = getResourceByType(userORG, catalogid, 1);
    } else if ($(node).hasClass("prev")) {
        if (groupsInfo.nowindex == 1) {
            alert("当前展示为第一组资源信息");
            return;
        }
        strResourceData = getResourceByType(userORG, catalogid, groupsInfo.nowindex - 1);
    } else if ($(node).hasClass("next")) {
        if (groupsInfo.nowindex == groupsInfo.totalpage) {
            alert("当前展示为最后一组资源信息");
            return;
        }
        strResourceData = getResourceByType(userORG, catalogid, groupsInfo.nowindex + 1);

    } else if ($(node).hasClass("last")) {
        if (groupsInfo.nowindex == groupsInfo.totalpage) {
            alert("当前展示为最后一组资源信息");
            return;
        }
        strResourceData = getResourceByType(userORG, catalogid, groupsInfo.totalpage);

    } else {
        return;
    }
    var jsonResourceData = changeStrToJsonOrArray(strResourceData, null, true, "json");
    initializeResource(jsonResourceData, 8);
}

//浏览资源
function clickView(node, resourceType) {
    var ulNode = node.parentNode.parentNode;
    var resourceID = $(ulNode).attr("guid");
    var position = $(ulNode).attr("position").split("\\");
    var filePath = position[position.length - 2] + "/" + position[position.length - 1];//路径加文件名
    var fileName = position[position.length - 1];//文件名
    var lastFileName = fileName.slice(fileName.lastIndexOf(".") + 1);//文件后缀名
    lastFileName = upperOrLower(lastFileName, "lower");

    var operaNum = updateResourceOperaNum(resourceID, "view");
    if (operaNum != -1) {
        // $(node.parentNode.parentNode).prev().find(".price .fa-eye").next().text(operaNum);
    }

    var url, fileUrl = null;
    switch (resourceType) {
        case 1:
        case "1":
        case 2:
        case "2":
        case 3:
        case "3":
        case 4:
        case "4":
            //parent.parent.window.document.getElementById('fmap').contentWindow.other_loadLayer(resourceID);
            //parent.parent.window.$('#header_tab2').click();
            window.open("/MapServer/Portal/layerViewer.html?id=" + resourceID)
            break;


            //window.location.href = url;
            //return;
            //$.ajax({
            //    type: 'get',
            //    url: url,
            //    async:false,
            //    cache: false,
            //    contentType: false,
            //    //processData: false, //默认为true，默认情况下，发送的数据将被转换为对象，设为false不希望进行转换
            //    //data: {
            //    //    fileName: fileName
            //    //}, //数据

            //    success: function (res) {
            //        console.log(res);
            //    },
            //    error: function (err) {
            //        console.log(err);
            //    }
            //});
            //return;
            //break;
        case 5:
        case "5":
            fileUrl = "http://" + selectOption.fileUploadIP + "/sw/upload/resourceDownload?fileName=" + filePath;
            switch (lastFileName) {
                case "jpg":
                case "jpeg":
                case "png":
                    url = "/BasePlatform/ModelDriven/showImg.html?file=" + encodeURIComponent(fileUrl);
                    break;
                case "pdf":
                    url = "/scripts/pdfJs/web/viewer.html?file=" + encodeURIComponent(fileUrl);
                    break;
                case "doc":
                case "docx":
                    url = fileUrl;
                    break;
                default:

            }
            break;
    }
    open(url, "_blank");
}
//浏览资源(新,ModeDrivenCatalog专用)
function clickViewNew(resourceID, position, resourceType) {
    position = position.split("\\");
    var filePath = position[position.length - 2] + "/" + position[position.length - 1];//路径加文件名
    var fileName = position[position.length - 1];//文件名
    var lastFileName = fileName.slice(fileName.lastIndexOf(".") + 1);//文件后缀名
    lastFileName = upperOrLower(lastFileName, "lower");

    var operaNum = updateResourceOperaNum(resourceID, "view");
    // if (operaNum!=-1) {
    //     $(node.parentNode.parentNode).prev().find(".price .fa-eye").next().text(operaNum);
    // }

    var url, fileUrl = null;
    switch (resourceType) {
        case 1:
        case "1":
            url = "/BasePlatform/DataServer/CreateDataSourceInfo.html?id=" + resourceID + "&mode=view";
            break;
        case 2:
        case "2":
            parent.window.document.getElementById('fmap').contentWindow.other_loadLayer(resourceID);
            parent.window.$('#header_tab2').click();
            return;
            break;
        case 3:
        case "3":
            url = "/BasePlatform/DataServer/CreateToolInfo.html?id=" + resourceID + "&mode=view";
            break;
        case 4:
        case "4":


            //window.location.href = url;
            //return;
            //$.ajax({
            //    type: 'get',
            //    url: url,
            //    async:false,
            //    cache: false,
            //    contentType: false,
            //    //processData: false, //默认为true，默认情况下，发送的数据将被转换为对象，设为false不希望进行转换
            //    //data: {
            //    //    fileName: fileName
            //    //}, //数据

            //    success: function (res) {
            //        console.log(res);
            //    },
            //    error: function (err) {
            //        console.log(err);
            //    }
            //});
            //return;
            //break;
        case 5:
        case "5":
            fileUrl = "http://" + selectOption.fileUploadIP + "/sw/upload/resourceDownload?fileName=" + filePath;
            switch (lastFileName) {
                case "jpg":
                case "jpeg":
                case "png":
                    url = "/BasePlatform/ModelDriven/showImg.html?file=" + encodeURIComponent(fileUrl);
                    break;
                case "pdf":
                    url = "/scripts/pdfJs/web/viewer.html?file=" + encodeURIComponent(fileUrl);
                    break;
                case "doc":
                case "docx":
                    url = fileUrl;
                    break;
                default:

            }
            break;
    }
    open(url, "_blank");
}
//编辑资源
function clickEdit(node, resourceType, resourceid) {
    var resourceID;
    if (resourceid) {
        resourceID = resourceid
    } else {
        resourceID = node.parentNode.parentNode.attributes.guid.value;

        var operaNum = updateResourceOperaNum(resourceID, "view");
        if (operaNum != -1) {
            $(node.parentNode.parentNode).prev().find(".price .fa-eye").next().text(operaNum);
        }

    }

    var url;
    switch (resourceType) {
        case 1:
        case "1":
        case 2:
        case "2":
        case 3:
        case "3":
        case 4:
        case "4":
            url = "/BasePlatform/DataServer/EditDataServer.html?id=" + resourceID + "&mode=edit";
            break;
            url = "/BasePlatform/DataServer/CreateDataSourceInfo.html?id=" + resourceID + "&mode=edit";
            var reg = /.*?_$/g;
            var isGroupNode = reg.exec(resourceID);
            if (isGroupNode) {
                alert("图层组不可编辑");
                return;
            }
            url = "/BasePlatform/DataServer/EditDataServer.html?id=" + resourceID + "&mode=edit";
            break;
            url = "/BasePlatform/DataServer/CreateToolInfo.html?id=" + resourceID + "&mode=edit";
            break;
            url = "/BasePlatform/DataServer/CreateMapInfo.html?id=" + resourceID + "&mode=edit";
            break;
            url = "/BasePlatform/DataServer/CreateFileInfo.html?id=" + resourceID + "&mode=edit";
            break;
    }
    open(url, "_blank");
}
//下载资源
function clickDownload(node, resourceType) {
    var ulNode = node.parentNode.parentNode;
    var resourceID = $(ulNode).attr("guid");
    var position = $(ulNode).attr("position").split("\\");
    var fileName = position[position.length - 2] + "/" + position[position.length - 1];
    var sourcename = $(ulNode).attr("sourcename");

    //更新操作数
    var operaNum = updateResourceOperaNum(resourceID, "down");
    if (operaNum != -1) {
        $(node.parentNode.parentNode).prev().find(".price .fa-download").next().text(operaNum);
    }

    switch (resourceType) {
        case 1:
        case "1":
        case 4:
        case "4":
            //var url = "http://"+selectOption.fileUploadIP+"/sw/upload/resourceDownload?fileName=" + fileName;
            //window.location.href = url;
            //break;
        case 5:
        case "5":
            var url = "http://" + selectOption.fileUploadIP + "/sw/upload/resourceDownload?fileName=" + fileName;
            window.location.href = url;
            break;
        default:
            return;
            break;
    }

}
//运行资源
function clickRundemo(node, resourceType) {
    var text = $(node).parent().parent().attr('sourcename');
    parent.showModelDriven(text);

    //更新操作数
    var resourceID = node.parentNode.parentNode.attributes.guid.value;
    var operaNum = updateResourceOperaNum(resourceID, "run");
    if (operaNum != -1) {
        $(node.parentNode.parentNode).prev().find(".price .fa-play-circle-o").next().text(operaNum);
    }
    //var resourceID = node.parentNode.parentNode.attributes.guid.value;
    //var result = addOrRemoveServer("insert", resourceID);
    //if (result == null) {
    //    alert("操作有误");
    //} else {
    //    alert(result.msg);
    //    parent.addOrRemoveServerInit && parent.addOrRemoveServerInit();
    //}
    //return;
    //alert("资源运行功能待开发");
    //updateResourceOperaNum(resourceID, "run");
}
//运行资源(新,ModeDrivenCatalog专用)
function clickRundemoNew(sourcename, guid, callback) {
    var text = sourcename;
    // parent.showModelDriven(text);

    //更新操作数
    var resourceID = guid;
    var operaNum = updateResourceOperaNum(resourceID, "run");
    if (operaNum != -1) {
        callback(operaNum);
    }
    //var resourceID = node.parentNode.parentNode.attributes.guid.value;
    //var result = addOrRemoveServer("insert", resourceID);
    //if (result == null) {
    //    alert("操作有误");
    //} else {
    //    alert(result.msg);
    //    parent.addOrRemoveServerInit && parent.addOrRemoveServerInit();
    //}
    //return;
    //alert("资源运行功能待开发");
    //updateResourceOperaNum(resourceID, "run");
}
//添加资源
function clickAdddemo(node, resourceType, resourceid) {
    var resourceID;
    if (resourceid) {
        resourceID = resourceid;
    } else {
        resourceID = node.parentNode.parentNode.attributes.guid.value;
    }

    var result = addOrRemoveServer("insert", resourceID);
    if (result == null) {
        alert("操作有误");
    } else {
        alert(result.msg);
        parent.addOrRemoveServerInit && parent.addOrRemoveServerInit();
    }
}

//更新浏览、下载、运行量
function updateResourceOperaNum(resourceID, operaType, operaNum) {
    var thisResult = -1;
    $.ajax({
        type: "post",
        async: false,
        // url: "/BaseAshx/Resource/ResourceAshx.ashx",  
        url:baseUrl+'resource/recordResource',
        data : {
            layerguid:resourceID,
            userNo:userinfo.userNo
        },
        // data: //发送到服务器的参数
        // {
        //     stype: "updateResourceOpreaNum",
        //     resourceid: resourceID,
        //     type: operaType,
        //     num: operaNum ? operaNum : ""
        // },
        datatype: "json",
        success: function (data) { 
            let result = JSON.parse(data) 
            if (result.code === 200) {
                layer.msg(result.msg,{
                    shade: 0.3,
                    time: 1000 // 1秒关闭
                })
                thisResult = data.split("|")[0];
            }
        },
        error: function (err) {
            layer.msg(err,{
                shade: 0.3,
                time: 1000 // 1秒关闭
            })
            // if (err.status == 405)
            //     top.location.href = '/login/LoginNew.aspx';
        }
    });
    return thisResult;
}

//资源搜索
function searchSource() {
    var ipt_searchSource = $("#ipt_searchSource").val();
    selectOption.filters.name = "%" + trimStr(ipt_searchSource) + "%";
    //if (selectOption.filter == "") {
    //    selectOption.filter = " tb.name like '%" + trimStr(ipt_searchSource) + "%' ";
    //}
    //else {
    //    selectOption.filter += " and tb.name like '%" + trimStr(ipt_searchSource) + "%' ";
    //}
    var strResourceData = getResourceByType(selectOption.org, selectOption.catalogid, 1);
    jsonCatalogData = changeStrToJsonOrArray(strResourceData, null, true, "json");
    initializeResource(jsonCatalogData, 8);
}
//获取行政区划
function getLowerXZQH(XZQDM) {
    var thisResult = null;
    $.ajax({
        type: "post",
        async: false,
        //url: "/BaseAshx/Map/DataServer.ashx",
        url: baseUrl + "map/getXZQHData",
        data: //发送到服务器的参数
        {
            //stype: "getXZQHData",
            XZQDM: XZQDM
        },
        datatype: "json",
        success: function (result) {
            thisResult = JSON.stringify(JSON.parse(result).data);
        },
        error: function (err) {
            // if (err.status == 405)
            //     top.location.href = '/login/LoginNew.aspx';
            layer.msg(err,{
                shade: 0.3,
                time: 1000 // 1秒关闭
            })
        }
    });
    thisResult = changeStrToJsonOrArray(thisResult, null, true, "json");
    return thisResult;
}
//获取数据年份
//获取数据比例
//获取数据精度
//获取高级查询下拉列表字典值
function getFilterDicValue(type) {
    var thisResult = null;
    $.ajax({
        type: "post",
        async: false,
        //url: "/BaseAshx/Resource/ResourceAshx.ashx",
        url: baseUrl + "dict/getSpecialDataDict",
        data: //发送到服务器的参数
        {
            //stype: "getSpecialDataDict",
            type: type
        },
        datatype: "json",
        success: function (result) {
            if (result) {
                thisResult = JSON.parse(result).data;
            }
        },
        error: function (err) {
            // if (err.status == 405)
            //     top.location.href = '/login/LoginNew.aspx';
            layer.msg(err,{
                shade: 0.3,
                time: 1000 // 1秒关闭
            })
        }
    });
    return thisResult;
}